﻿#include <QTreeWidget>
#include <QVBoxLayout>
#include <QFileInfo>
#include <QDir>
#include <Resources.h>
#include <FileSystemTreeWidget.h>
#include <FileSystemTreeWidgetItem.h>
#include "FileExplorerWindow.h"

namespace Domy {

FileExplorerWindow::FileExplorerWindow(ActionEnableCtrl ctrl, QWidget *parent) :
    DockWidgetInterface(ctrl, parent),
    m_tree_widget(new FileSystemTreeWidget(this))
{
    QVBoxLayout *l = new QVBoxLayout(this);
    l->addWidget(m_tree_widget);
    l->setContentsMargins(5, 0, 0, 0);
    this->setLayout(l);

    initFileExplorer();

    connect(m_tree_widget, SIGNAL(signalOpenFile(const QString &)), this, SIGNAL(signalOpenFile(const QString &)));
}

FileExplorerWindow::~FileExplorerWindow()
{

}

QDockWidget *FileExplorerWindow::createDockWidget()
{
    QDockWidget *dock_widget = new QDockWidget(tr("File Explorer"), parentWidget());
    dock_widget->setObjectName("FileExplorerWindow");
    dock_widget->setFeatures(dock_widget->features() & ~QDockWidget::DockWidgetFloatable);
    dock_widget->setWidget(this);

    return dock_widget;
}

void FileExplorerWindow::initFileExplorer()
{
    m_tree_widget->setHeaderContent(tr("Computer"), GET_ICON("computer"));

    // 加载盘符
    QFileInfoList fi_list = QDir::drives();
    m_tree_widget->add(fi_list);
}

} // namespace Domy
